<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}
//$opid = $_REQUEST['intoptionid'];			
				
// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit") {				
				$insert = "INSERT INTO `tblproductattributes` (`intproductid`, `intoptionid`, `intoptionvalueid`, `decprice`, `charprefix`)	VALUES ('".mysql_real_escape_string($_REQUEST['product'])."', '".mysql_real_escape_string($_REQUEST['option'])."', '".mysql_real_escape_string($_REQUEST['optvalue'])."', '".mysql_real_escape_string($_REQUEST['decprice'])."',  '".mysql_real_escape_string($_REQUEST['charprefix'])."')";				
				$sql=$obj_db->insert($insert);
				header("location:prodattr.php?msg=add");
				die();
}

// UPDATE the record
$product= "";
$option = "";
$optvalue = "";
$decprice1 = "";
$charprefix1 = "";
$action=1;
$btn = "Submit";

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{	
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  $_REQUEST['intid'];
		$sql = "select * from `tblproductattributes` where `intattributeid` ='$screen_id'";
		$result = $obj_db->select($sql);
		if(count($result)<=0) {
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				$product = stripslashes($row['intproductid']);
				$option = stripslashes($row['intoptionid']);
				$optvalue = stripslashes($row['intoptionvalueid']);
				$decprice1 =  stripslashes($row['decprice']);		
				$charprefix1 = stripslashes($row['charprefix']);		
				$action=2;
				$btn = "Update";
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update") {
			$product = mysql_real_escape_string($_REQUEST['product']);
			$option = mysql_real_escape_string($_REQUEST['option']);
			$optvalue = mysql_real_escape_string($_REQUEST['optvalue']);
			$decprice = mysql_real_escape_string($_REQUEST['decprice']);
			$charprefix = mysql_real_escape_string($_REQUEST['charprefix']);
			$sql_upd ="UPDATE `tblproductattributes`
			SET `intproductid` = '$product', `intoptionid` = '$option',
			`intoptionvalueid` = '$optvalue', `decprice` = '$decprice',
			`charprefix` = '$charprefix'
			where `intattributeid` ='$screen_id'";			 
			$result = $obj_db->edit($sql_upd);
			$action=1;
			header("location:prodattr.php?msg=edit");
			die();
		}
	}
}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  mysql_real_escape_string($_REQUEST['intid']);
		
		$sqldel= "DELETE FROM `tblproductattributes` WHERE `intattributeid` ='$id'";		
		$query1 = mysql_query($sqldel);
		
		header("location:prodattr.php?msg=del");
		die();
	}
}

?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/prodattr.js"></script>

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td align="center" valign="top" ><?php include(INC."top.inc.php");?></td>
</tr>
<tr>
<td valign="top">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
  <tr>
	<td valign="top">
	  <?php   
   if(isset($_REQUEST['script'])) {
	if(trim($_REQUEST['script'])=='addprodattr' || trim($_REQUEST['script'])=='editprodattr') {
	?>
	<form name="prodattr" method="post" action="">

	  <table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
      <tr class="bg1">
        <td colspan="5" align="center"><strong>
          <?php if($_REQUEST['script']=='addprodattr'){echo "Add New Product Details...";}
	if($_REQUEST['script']=='editprodattr'){echo "Edit Product Details...";}?>
        </strong></td>
      </tr>
      <tr>
        <td width="4%">&nbsp;</td>
        <td width="26%" align="left">&nbsp;</td>
        <td width="3%">&nbsp;</td>
        <td width="63%" align="right">(* All fields are Required)</td>
        <td width="4%">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td align="right" class="sltimg">*Option Name. </td>
        <td>:</td>
        <td align="left"><select name="option" id="option" onChange="this.form.submit();">
          <option value="0">Select Option</option>
          <?php 
		  			if(isset($_REQUEST['option']) && ($_REQUEST['option'])!=0)
					{
						$option=$_REQUEST['option'];
					}
						$sqlopt = "select * from `tbloptionvalues`";
						$resopt = $obj_db->select($sqlopt);
						if(count($resopt)>0)
						{
							for($c1=0;$c1<count($resopt);$c1++)
							{							
					?>
          <option value="<?php echo stripslashes($resopt[$c1]['intid']);?>"<?php if($resopt[$c1]['intid'] == $option){echo "selected";} ?>>
            <?php echo stripslashes($resopt[$c1]['varoptionvaluename']);?>
            </option>
          <?php
							}
						}
					?>
        </select></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td align="right" class="sltimg">*Option Value</td>
        <td>:</td>
        <td align="left"><select name="optvalue" id="optvalue">
            <option value="0">Select Option Value</option>
            <?php 
					$optval="";
					if(isset($_REQUEST['optvalue']) && ($_REQUEST['optvalue']))
					{
						$optval=$_REQUEST['optvalue'];
					}
		  				$coun=issetvar("option","");
						
						$sqloval = "select * from `tblproductoptions` where intoptionid='$option'";
						$resval = $obj_db->select($sqloval);
						if(count($resval)>0)
						{
							for($c2=0;$c2<count($resval);$c2++)
							{
					?>
            <option value="<?php echo stripslashes($resval[$c2]['intid']);?>"<?php if($optval == $resval[$c2]['intid']){echo "selected";}?> ><?php echo stripslashes($resval[$c2]['varoptionname']);?></option>
            <?php
							}
						}
					?>
          </select></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td align="right" class="sltimg">*Product No. </td>
        <td>:</td>
        <td align="left"><select name="product" id="product">
          <option value="0">Select Product</option>
          <?php 
						$sqlprod = "select * from `tblproducts`";
						$resprod = $obj_db->select($sqlprod);
						if(count($resprod)>0)
						{
							for($c=0;$c<count($resprod);$c++)
							{							
		?>
          <option value="<?php echo stripslashes($resprod[$c]['intprodid']);?>"<?php if($resprod[$c]['intprodid'] == $product){echo "selected";} ?>>
          <?php echo stripslashes($resprod[$c]['intprodid']);?>
          </option>
          <?php
							}
						}
		?>
        </select></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td align="right" class="sltimg">*Addtional Price </td>
        <td>:</td>
        <td align="left"><input name="decprice" type="text" id="decprice" value="<?php echo stripslashes($decprice1);?>" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td align="right" class="sltimg">*Prefix(+/-)</td>
        <td>:</td>
        <td align="left"><input name="charprefix" type="text" id="charprefix" value="<?php echo stripslashes($charprefix1);?>" /></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" align="left">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo stripslashes($btn);?>" onClick="return check();"/></td>
      </tr>
      <tr>
        <td colspan="5" align="center">&nbsp;</td>
      </tr>
    </table>
	</form>
	<?php
	}
}
else
{
	//if(isset($_REQUEST['intoptionid']) && isset($_REQUEST['intoptionid'])!="")
	//{
?>
	<br />
	<table width="75%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
      <tr class="bg1">
	  <?php 
	  if(isset($_REQUEST['intoptionid']) && isset($_REQUEST['intoptionid'])!="")
		{$pid=$_REQUEST['intoptionid'];}	
	  ?>
        <td colspan="5" align="left"><strong class="bg1">Product Attribute  Details...</strong>&nbsp;<a href="prodattr.php?script=addprodattr" class="aa"></a></td>
        <td align="center"><a href="prodattr.php?script=addprodattr" class="aa">[NEW]</a></td>
        <td align="center"><a href="#" Title="Click here to Go Back" onClick="history.go(-1);" class="aa">Go BACK</a></td>
      </tr>
      <tr>
         <?php 
	   $rows="";
	 if(isset($_REQUEST['page']) && ($_REQUEST['page'])!="")
	 {
	 	$rows=$_REQUEST['page'];
	  }	
	  ?><form name="form1" action="" method="post">
              <td colspan="8" align="left">
			  
			  Row per Page:
                <select name="page" onChange="document.form1.submit();">
                  <option value="0"<?php if($rows=='0'){echo "selected";}?>>All</option>
                  <option value="5"<?php if($rows=='5'){echo "selected";}?>>5 Per Page</option>
                  <option value="10"<?php if($rows=='10'){echo "selected";}?>>10 Per Page</option>
                  <option value="15"<?php if($rows=='15'){echo "selected";}?>>15 Per Page</option>
                </select>
				
				</td></form>
				
        </tr>
      <tr class="tblbg3">
        <td align="center">Product No </td>
		<td align="center">Option Name </td>
        <td align="center"><strong>Option Values</strong></td>
        <td align="center"><strong>Value Price</strong></td>
        <td align="center"><strong>Prefix</strong></td>
        <td align="center"><strong>Edit</strong></td>
        <td colspan="2" align="center"><strong>Delete</strong></td>
      </tr>
<?php	  
	  	/**************************************
				PAGING CODE START
		**************************************/
if(isset($_REQUEST['page']) && ($_REQUEST['page'])!=0)
			{
				$rows=$_REQUEST['page'];
				$rowperpage=$rows;
			}else{$rowperpage=$rows=10000;}
			$tablename="tblproductattributes";
			$per_page_keywords= "";
			$per_page_sorts="";
			include("system/paging.inc.php");

		/**************************************
				PAGING CODE ENDING
		**************************************/
		
		$sql = "SELECT * 
		from  ".$tablename."	
		Limit ".($page_no*$row_per_page).",".$row_per_page;

   		//$sql="select * from `tblproductattributes`";
		
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intattributeid'];
?>
		<tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onmouseout="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
		<td align="center"><?php echo $result[$i]['intproductid'];?></td>
		<td align="center">
		<?php
			$sqlonm = "SELECT * FROM `tbloptionvalues` WHERE `intid`=".$result[$i]['intoptionid'];
			$resonm = $obj_db->select($sqlonm);
			
			if(count($resonm)>0)
			{
				echo $resonm[0]['varoptionvaluename'];
			}
		?>		</td>
		<td align="center"><?php 
		$optid=$result[$i]['intoptionvalueid'];
		$sqlprop="select * from tblproductoptions where intid='$optid'";
		$respropt=$obj_db->select($sqlprop);
		if($respropt){echo $respropt[0]['varoptionname'];}
		?></td>
		<td align="center"><?php echo stripslashes($result[$i]['decprice']);?></td>
		
        <td align="center"><?php echo stripslashes($result[$i]['charprefix']);?></td>
		<td align="center"><a class="link" Title="Click here to Edit" href="prodattr.php?script=editprodattr&amp;a=2&amp;intid=<?php echo stripslashes($id);?>"><img src="images/edit.bmp" border="0"/></a></td>
        <td colspan="2" align="center"><a Title="Click here to Delete" href="prodattr.php?a=3&amp;intid=<?php echo stripslashes($id);?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
		</tr>
      <?php }}?>
      <tr>
        <td colspan="10" align="center"><?php pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);?></td>
      </tr>
    </table>
    
    <?php } //}?></td>
  </tr>
</table>

</td>
</tr>
<tr><td align="center">&nbsp;</td>
</tr>
</table>
</body>
</html>

